<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;

?>
<style>
    .clear-data,.isVerify{float:right!important;}
	.table tr td a{float: left;margin-top: 18px;}
</style>

		<div class="row borB">
			<div class="container lh30">
				<a class="topNav" href="<?= Url::to(['/system/site/index']) ?>"><img src="<?= Yii::getAlias('@web/backend/img/home/home.png') ?>" alt="首页"/>返回首页</a>
		</div>

		</div>
		<div class="right_site right_52">
			<span class="z">
				<form name="form" action=""  method="post" >
					<input type="hidden" name="" value="" id="upload_id" />
					<input type="submit" style="display:none;" id="upload_sub" />
				</form>

			</span>
		</div>
		<div class="container">
			<div class="mg20-y">
				<a href="javascript:openAdd()" class="add_upload btnBg mr20">新增分店</a>
				<a href="javascript:openPass()" class="add_upload btnBg">修改老板密码</a>

				<p class="pull-right text-right">清空数据后，该分店所有收银及库存等业务数据将被销毁，且无法恢复；<br>
					如有线上店铺，清空数据后，该分店的线上店铺因清空将暂时关闭，请与客服联系重新开通
				</p>
			</div>

			<div class="table-responsive" style="width:100%;">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>日期</th>
							<th>店长账号</th>
							<th>分店名称</th>
							<th>是否开通线上店铺</th>
							<th>操作</th>
						</tr>
					</thead>
					<?php foreach ($model as $r) {?>
					<tr>
						<td><?=Html::encode($r['create_time'])?></td>
						<td><?=Html::encode($r['login_name'])?></td>
						<td><?=Html::encode($r['shop_name'])?></td>
						<td>
						<?php if($r['isopen_online'] == 0){?>
						未开通
						<?php }elseif($r['isopen_online'] == 1){?>
						已开通
						<?php }else{?>
						审核中
						<?php }?>
						</td>
						<td>
						    <a href="javascript:openEdit(<?=$r['shop_id']?>)"  class="edit btn btn-sm btn-borB mr20">编辑</a><input type="submit" style="display:none;" />
							<a class="btn btn-sm btn-borB" href="<?=Url::toRoute(['shopmanage/disable','id' => $r['shop_id']]) ?>">清除账号</a>
							<?php if($r['isopen_online'] == 2){?>
							    <a class="btn btn-sm btn-borB isVerify" href="javascript:void(0)" did="<?=$r['shop_id']?>" dstate="<?=$r['isopen_online']?>" durl="<?=Url::toRoute(['shopmanage/cleardata']) ?>">清空数据</a>
							<?php }else{?>
							    <a class="btn btn-sm btn-borB clear-data" href="javascript:void(0)" did="<?=$r['shop_id']?>" dstate="<?=$r['isopen_online']?>" durl="<?=Url::toRoute(['shopmanage/cleardata']) ?>">清空数据</a>
						    <?php }?>  
						</td>
					</tr>
					<?php }?>
				</table>
			</div>
				<div class="page">
<?=LinkPager::widget([
    'pagination' => $page,
	'firstPageLabel' => '首页',
	'nextPageLabel' => '下一页',
	'prevPageLabel' => '上一页',
	'lastPageLabel' => '末页',
]); ?>
				</div>

		</div>

<?php $this->beginBlock('js_index') ?>
function initSetState() {
        $('.clear-data').on('click', function(){
            obj = $(this);
            var id = obj.attr('did');
            var url = obj.attr('durl');
            var state = obj.attr('dstate');
            layer.confirm(
                '<div style="margin-top: 15px;padding: 0 30px;"><div style="font-size: 16px;margin-bottom: 25px;">确定清空吗？</div>清空后该分店所有收银及库存等业务数据将被销毁，且<i class="red">无法恢复</i>，请慎重</div>',
                {
                    icon: 3,
                    title: '系统提示',
                    btn: ['确 定', '取 消']
                },
                function(index){
                    layer.close(index);
                    $.post(
                        url,
                        {id: id,state: state},
                        function(data){
                            if(data.status == 10000) {
                                layer.confirm(data.errmsg, {icon: 3, title:'提示'}, function(index){
                                    location.reload(true);
                                });
                                
                            } else {
                                layer.closeAll();
                                layer.alert(data.errmsg);
                            }
                        },
                        'json'
                    );
                },
                function(index){
                    layer.close(index);
                }
            );
        });
    };
 $(function(){
    initSetState();
    $('.isVerify').on('click', function(){
        layer.alert('无法清空，该分店有线上店铺尚在审核中，待开通后方可清空', {icon: 2});
    });
    
 });   
function openAdd()
{
	layer.open({
		type: 2,
		area: ['570px', '450px'],
		title: '新增分店',
		fix: false, //不固定
		maxmin: true,
		content:"<?= Url::to(['/business/shopmanage/add', 'type' => 'boss']) ?>"
	});
};

function openPass()
{
	layer.open({
		type: 2,
		title: '修改密码',
		fix: false, //不固定
		maxmin: true, //开启最大化最小化按钮
		area: ['570px', '350px'],
		content: "<?= Url::to(['/system/public/password', 'type' => 'boss']) ?>"
	});
}
function openEdit(id)
{
layer.open({
type: 2,
area: ['570px', '450px'],
title: '编辑分店',
fix: false, //不固定
maxmin: true,
content:"<?= Url::to(['/business/shopmanage/edit']) ?>?id="+id
});
};
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js_index'], $this::POS_END); ?>

